import mongoose from 'mongoose'

const Visitor = mongoose.model('Visitor')

export const saveVisitor = async ({cip, cid, cname}) => {
  const visitor = await Visitor.findOne({
    cip
  }).exec()

  if (!visitor) {
    await new Visitor({cip, cid, cname, visitCount: 1}).save()
  } else {
    visitor.visitCount++
    await visitor.save()
  }
  return {
    success: true
  }
}